//
//  ANShoppingCarCellFrame.m
//  Ants
//
//  Created by ZHM on 16/8/31.
//  Copyright © 2016年 ZHM. All rights reserved.
//

#import "ANShoppingCarCellFrame.h"

static CGFloat MAIN_CELL_HEIGHT = 100;

@implementation ANShoppingCarCellFrame

- (void)setShoppingItem:(ANBDShoppingItem *)shoppingItem {
    _shoppingItem = shoppingItem;
    
    CGFloat selectBtX = 0;
    CGFloat selectBtY = 0;
    UIImage *btimg = [UIImage imageNamed:@"ic_cb_normal.png"];
    CGFloat selectBtW = btimg.size.width + 20;
    CGFloat selectBtH = MAIN_CELL_HEIGHT;
    _selectBt = CGRectMake(selectBtX, selectBtY, selectBtW, selectBtH);
    
    _icon = CGRectMake(CGRectGetMaxX(_selectBt) + 5, ANCellMargin, 80, 80);
    
    
    CGFloat textX = CGRectGetMaxX(_icon) + 5;
    CGFloat textY = ANCellMargin;
    CGFloat textW = ANscreenW - CGRectGetMaxX(_icon) - ANCellMargin * 2;
    CGSize textSize = [shoppingItem.product.title sizeOfTextWithMaxSize:CGSizeMake(textW, MAXFLOAT) font:ANDetailLabelSize];
    _nameLabelFrame = (CGRect){{textX,textY},textSize};
    
    NSDecimalNumber *price = shoppingItem.product.price;
    _priceLabelText = [NSString stringWithFormat:@"￥%@", price];
    NSDictionary *attrib = @{NSFontAttributeName:ANDetailLabelSize};
    CGSize priceLabelSize = [_priceLabelText sizeWithAttributes:attrib];
    _priceLabel = (CGRect){{_nameLabelFrame.origin.x,CGRectGetMaxY(_icon) - priceLabelSize.height},priceLabelSize};

    _changeCountView = CGRectMake(ANscreenW - 98 - ANCellMargin, MAIN_CELL_HEIGHT - 35, 98, 35);
    _soldOutLab = CGRectMake(_changeCountView.origin.x - 40, _priceLabel.origin.y, 35, _priceLabel.size.height);
    
    _otherView = CGRectMake(0, 0, 0, 0);
    _cellHeight = CGRectGetMaxY(_otherView) + 100;
    
    _count = [shoppingItem.quantity integerValue];
}

@end
